package GA;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;

import Operations.Operation;
public class ConstructorDeclared extends Operation implements Comparable<ConstructorDeclared>, Cloneable{
	private  String refrence;
	private final Class<?> clazz;
	private  String[] params;
	private List<Field> constantsList;
	private final Class<?>[] ParamsType;
	private final Constructor<?> cons;
	public ConstructorDeclared(String refrence, Class<?> clazz, String[] params,Class<?>[] ParamsType, List<Field> constantsList,Constructor<?> cons) {
		this.refrence=refrence;
		this.clazz = clazz;
		this.params = params;
		this.ParamsType=ParamsType;
		this.constantsList= constantsList;
		this.cons=cons;
	}
	
	public Class<?> getClazz() {
		return clazz;
	}
	public String getRefrence() {
		return refrence;
	}
	public void setRefrence(String ref) {
		this.refrence=ref;
	}

	public String[] getParams() {
		return params;
	}
	public void setParams(String[] params) {
		this.params=params;
	}

	public Class<?>[] getParameterTypes() {
		return ParamsType;
	}
	public List<Field> getConstantsList(){
		return this.constantsList;
	}
	public Constructor<?> getCons(){
		return this.cons;
	}
	@Override
	public int compareTo(ConstructorDeclared o) {
		final int refrenceResult = refrence.compareTo(o.refrence);
		if(refrenceResult != 0) return refrenceResult;
		return 0;

	}
	@Override
	public ConstructorDeclared clone() {
		return new ConstructorDeclared(this.refrence,
		this.clazz,
		this.params.clone(),
		this.ParamsType,
		this.constantsList,
		this.cons
);
	}
	@Override
	public String toString() {
//		System.out.print(b)
		StringBuilder sb = new StringBuilder(clazz.getName() + " "+ refrence+ " = new "+ clazz.getName()).append("(");
//		System.out.println("ConstructorDeclared.toString: "+ sb.toString() + "paramTpe:"+ this.ParamsType.length+ "params value:"+ this.params.length);
		int i=0;
		boolean first = true;
		for(Class<?> p : this.ParamsType) {

			if(first) first = false;
			else sb.append(",");

	//			sb.append( ParamsType[i].toString()  );

			if(this.params[i]==null)
				sb.append("null");
			else
			if(p.equals(java.lang.String.class) && !params[i].equals("null"))
				sb.append("\"" + params[i].toString() + "\"" );
			else
				sb.append( params[i].toString()  );
			i++;
		}

		return sb.append(")").toString();
	}

}
